/**
 * Created by mapbar_front on 2019/5/25.
 */
import React,{Component} from 'react';
//原型链
/*
function SuperType(name){
    this.property = name;
}
SuperType.prototype.getSuperValue = function(){
    return this.property;
}
function SubType(name){
    this.subproperty = name;
}
//继承了SuperType
SubType.prototype = new SuperType('超类');

SubType.prototype = {
    getSubValue: function(){
        return this.subproperty;
    }
}

SubType.prototype.getSubValue = function(){
    return this.subproperty;
}
SubType.prototype.getSuperValue = function(){
    return this.property = '重写超类';
}
var instance = new SubType('子类');
console.log(instance.getSuperValue()); //'超类'
//console.log(instance.constructor); //SuperType
console.log(instance.getSubValue());

//console.log(new SuperType('tianxia666').getSuperValue());

function SuperType(){
    this.name = '超类';
}
SuperType.prototype.sayName = function(){
    return this.name;
}
function SubType(){
    //继承
    SuperType.call(this,'tianxia');
}
var instance = new SubType();
//console.log(instance.sayName()); //TypeError: instance.sayName is not a function



function SuperType(name){
    this.name = name;
    this.colors = ['yellow','blue'];
}
SuperType.prototype.sayName = function(){
    console.log(this.name);
}
function SubType(name,age){
    //继承属性
    SuperType.call(this,name);
    this.age = age;

}
SubType.prototype = new SuperType();
SubType.prototype.sayAge = function(){
    console.log(this.age);
}

var instance1 = new SubType('子类1',123);
instance1.colors.push('green');
console.log(instance1.colors);
instance1.sayName();
instance1.sayAge();

var instance2 = new SubType('子类2',456);
console.log(instance2.colors);
instance2.sayName();
instance2.sayAge();

function object(o){
    //创建一个临时的构造函数F
    function F(){}
    F.prototype = o;
    return new F();
}
var person = {
    name: 'xiao',
    colors: ['yellow','blue']
}

// var anotherPerson = new Object(person);
// console.log(anotherPerson);
// anotherPerson.name = 'tianxia';
// anotherPerson.colors.push('green');
// console.log(anotherPerson);
//
// var yetAnotherPerson =  new Object(person);
// console.log(yetAnotherPerson);
// yetAnotherPerson.colors.push('red');
// console.log(yetAnotherPerson);
//
// console.log(person);

//Object.create()规范化了原型式继承，这个方法接受两个参数：
// 一个用做新对象原型的对象
// 一个为新对象定义额外属性的对象。

// var anotherPerson1 = Object.create(person);
// console.log(anotherPerson1);
// anotherPerson1.name = '运动有利于健身';
// anotherPerson1.colors.push('red');
// console.log(anotherPerson1);
//
// var yetAnotherPerson1 = Object.create(person);
// console.log(yetAnotherPerson1);
// yetAnotherPerson1.name = '以后提倡运动';
// yetAnotherPerson1.colors.push('purple');
// console.log(yetAnotherPerson1);
*/
/*
var anotherPerson = Object.create(person,{
    name: {
        value:'运动'
    }
});
console.log(anotherPerson.name);

function createAnother(original){
    //通过调用函数创建一个新对象
    var clone = object(original);
    clone.sayHi = function(){
        console.log(this.name);
    }
    return clone;
}
var person = {
    name: 'tianxia234',
    colors: ['yellow','blue']
}
function object(o){
    function F(){}
    F.prototype = o;
    return new F();
}

var anotherPerson = createAnother(person);
anotherPerson.sayHi();
console.log(person);

function SuperType(name){
    this.name = name;
    this.colors = ['yellow','blue'];
}
SuperType.prototype.sayName = function(){
    console.log(this.name);
}


function SubType(name){
    SuperType.call(this,name);
}
SubType.prototype.constructor = SubType;
SubType.prototype.sayAge = function(){
    console.log(this.age);
}

var instance = new SubType('tianxia',123);

//6.3.4原型式继承
function object(o){
    function F(){}
    F.prototype = o;
    return new F();
}
var person = {
    name: 'tianxia666',
    colors: ['blue','yellow','green']
}
var otherPerson = object(person);
console.log(otherPerson);
otherPerson.name = 'xiao666';
otherPerson.colors.push('purple');
console.log(otherPerson);

var yetOtherPerson = object(person);
yetOtherPerson.name = '崇尚运动';
yetOtherPerson.colors.push('red');
console.log(yetOtherPerson);

//6.3.5 寄生式继承
function createAnOther(original){
    //通过调用函数创建一个新对象
    var clone = object(original);
    //以某种方式来增强对象
    clone.sayHi = function(){
        console.log('Hi');
    }
    return clone; //返回这个对象
}
var person = {
    name: 'tianxia6',
    color: ['red']
}
var other = createAnother(person);
console.log(other);
other.name = '我需要你的强大';
console.log(other);


//6.3.6 寄生组合继承
function object(o){
    function F(){}
    F.prototype = o;
    return new F();
}

function inheritPrototype(SubType,SuperType){
    var prototype = object(SuperType.prototype);
    SubType.prototype.constructor = SubType;
    SubType.prototype = prototype;
}

function SuperType(name){
    this.name = name;
    this.colors = ['red']
}
SuperType.prototype.sayName = function(){
    console.log(this.name);
}

function SubType(name,age){
    //继承属性
    SuperType.call(this,name);
    this.age = age;
}
inheritPrototype(SubType,SuperType);

var instance1 = new SubType('tianxia123',123);
console.log(instance1);
instance1.colors.push('white');
console.log(instance1.colors);
var instance2 = new SubType('xiao456',456);
instance2.colors.push('#000');
console.log(instance2.colors);

function SuperType(name){
    this.name = name;
    //定义在构造函数内部的方法无法复用
    // this.getSuperValue = function(){
    //     console.log(this.name);
    // }
}
SuperType.prototype.getSuperValue = function(){
    console.log(this.name);
}
function SubType(name){
    SuperType.call(this,name);
}
SubType.prototype.getSubValue = function(){
    console.log(this.name);
}
var instance1 = new SubType('tianxia666');
instance1.getSubValue(); //TypeError: instance1.getSuperValue is not a function
 */
class Inherits extends Component{
    constructor(props){
        super(props);
    }
    render(){
        return(
            <div>
                Inherits
            </div>
        )
    }
}

export default Inherits;